package io.renren.modules.medical.controller;

import io.renren.common.result.Result;
import io.renren.common.validator.group.AddGroup;
import io.renren.modules.medical.entity.IllSubEntity;
import io.renren.modules.medical.entity.PatientDoctorRelativeEntity;
import io.renren.modules.medical.service.PatientDoctorRelativeService;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 病人医生关系接口
 * @author Luo Sheng
 * @school YiBin university
 * @create 2023-06-06 17:26
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("medical/relative")
public class PatientDoctorRelativeController {

    private final PatientDoctorRelativeService patientDoctorRelativeService;

    /**
     * 新增患者病情信息
     */
    @RequiresPermissions("relative:addpatientsub")
    @PostMapping("/addPatientSub")
    public Result<String> addPatientSub(@RequestBody @Validated(AddGroup.class) PatientDoctorRelativeEntity patientDoctorRelativeEntity){
        patientDoctorRelativeService.addPatientSub(patientDoctorRelativeEntity);
        return Result.success(null);
    }

    /**
     * 根据父id获取到子id
     */
    @GetMapping("/getListByParent")
    public Result<List<IllSubEntity>> getListByParentId(Long subId, Long patientId){
        List<IllSubEntity> listResult = patientDoctorRelativeService.getChildrenByParentId(subId, patientId);
        return Result.success(listResult);
    }
}
